import sys
import os

from PyQt5.QtWidgets import QApplication, QMessageBox, QWidget, QPushButton, QLabel, QHBoxLayout, QVBoxLayout, QGridLayout
from PyQt5.QtGui import QIcon, QFont
from PyQt5.QtCore import pyqtSlot
#导入我们自己定义的模块
from dialog import Dialog
from stuSysWindow import StuSysWindow
from teacherSysWindow import TeacherSysWindow

class MainWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.setup_ui()

    def setup_ui(self):
        self.setWindowTitle("学生信息管理系统")
        self.resize(500, 500)
        self.move(500, 200)
        #创建标签并加入到水平布局管理器中
        self.label = QLabel()
        self.label.setText("     欢迎使用学生信息管理系统")
        self.label.setFont(QFont("Roman times", 20, QFont.Bold))
        self.hbox = QHBoxLayout()
        self.hbox.addWidget(self.label)
        #创建两个按钮并加入到网格布局管理器中
        self.stuButton = QPushButton("学生")
        self.teaButton = QPushButton("老师")
        self.grid = QGridLayout()
        self.grid.addWidget(self.teaButton, 1, 0)
        self.grid.addWidget(self.stuButton, 1, 1)
        #整个父窗口使用垂直布局管理器管理
        self.vbox = QVBoxLayout()
        self.vbox.addLayout(self.hbox)
        self.vbox.addLayout(self.grid)
        #设置QWidget的布局管理器
        self.setLayout(self.vbox)
        #设置信号槽
        self.stuButton.clicked.connect(self.on_click_stu_Button)
        self.teaButton.clicked.connect(self.on_click_tea_Button)

    @pyqtSlot()
    def on_click_stu_Button(self):
        dialog = Dialog(0)
        while True:
            dialog.exec()
            status = dialog.get_status()
            if status == 0:
                QMessageBox.information(self, "提示", "登录成功", QMessageBox.Yes, QMessageBox.Yes)
                self.hide()
                self.stuSysWindow = StuSysWindow(dialog.get_stu_id())
                self.stuSysWindow.show()
                break
            else:
                QMessageBox.information(self, "提示", "账号或密码错误", QMessageBox.Yes, QMessageBox.Yes)
                continue

    @pyqtSlot()
    def on_click_tea_Button(self):
        dialog = Dialog(1)
        while True:
            dialog.exec()
            status = dialog.get_status()
            if status == 0:
                QMessageBox.information(self, "提示", "登录成功", QMessageBox.Yes, QMessageBox.Yes)
                self.hide()
                self.teaSysWindow = TeacherSysWindow()
                self.teaSysWindow.show()
                break
            else:
                QMessageBox.information(self, "提示", "账号或密码错误", QMessageBox.Yes, QMessageBox.Yes)
                continue

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec_())